#include <iostream>
#include <vector>
using namespace std;
class UFSet {
    vector<int> fa;
public:
    UFSet(int n) : fa(n) {
        for (int i = 0; i < n; ++i) {
            fa[i] = i;
        }
    }

    void connect(int a, int b) {
        fa[find(b)] = find(a);
    }

    int find(int x) {
        if (fa[x] == x) return x;
        return fa[x] = find(fa[x]);
    }

    bool isConnect(int a, int b) {
        return find(a) == find(b);
    }

    void disconnect(int x) {
        fa[x] = x;
    }
};